#ifndef STATEBASE_H
#define STATEBASE_H

#include <QObject>
#include <QStyle>
#include <QWidget>

class StateBase
{
public:
    explicit StateBase(){}
    virtual ~StateBase(){}
    //Q_PROPERTY(QString _state READ state WRITE setState NOTIFY sigStateChanged USER true)

    //Q_SIGNAL void sigStateChanged();
    QString state() {return _state;}
    void setState(QString state){
        if(_state == state){
            return;
        }
        _state=state;
        repolish();
    }

    void setState(const QString &name, bool enable){
        if(enable){
            if(_states.contains(name)){
                return;
            }
            _states<<name;
        }
        else{
            if(!_states.contains(name)){
                return;
            }
            _states.removeOne(name);
        }
        setState(toStateString());
    }

protected:
    virtual void repolish() = 0;
    QString _state;
    QStringList _states;

private:
    QString toStateString(){
        QString s;
        for (int index=0; index<_states.count(); index++) {
            s += _states[index];
            if(index+1<_states.count()){
                s += '|';
            }
        }
        return s;
    }
};

#endif // STATEOBJECT_H
